package com.exam.control;

import com.exam.utils.JdbcControl;
import com.exam.view.ShowChoiceOrWrite;

import java.sql.SQLException;
import java.util.Collection;
import java.util.TreeMap;

public class ExamAndRoom extends ShowChoiceOrWrite {
    public void exam(int number) throws SQLException {
        int testNumber= JdbcControl.selectReturnInt("examination_room","examinationNumber","number="+number);
        JdbcControl.returnSetRs("bankNumber,questionNumber","examination","testNumber="+testNumber);
        //
        TreeMap<Integer,Integer> bankNumberListt=new TreeMap<>();
        while(JdbcControl.getRs().next()){
            bankNumberListt.put(JdbcControl.getRs().getInt("questionNumber"), JdbcControl.getRs().getInt("bankNumber"));
        }
        Collection<Integer> bankNumbers = bankNumberListt.values();
        for(Integer bankNumber:bankNumbers){

            //第几道题的实现
            //System.out.println("第");
            //

            String sql=null;
            String questionType= JdbcControl.selectReturnString("question_bank","questionType","bankNumber="+bankNumber);
            if("单选".equals(questionType)||("多选".equals(questionType))){
                sql="select choice_question.* from question_bank right outer join choice_question on" +
                        " question_bank.questionNumber=choice_question.questionNumber where bankNumber="+bankNumber;
                JdbcControl.setRs(JdbcControl.getStmt().executeQuery(sql));
                if(JdbcControl.getRs().next()){
                    choice(); //展示题目
                }
            }else{
                sql="select write_question.* from question_bank right outer join write_question on" +
                        " question_bank.questionNumber=write_question.questionNumber where bankNumber="+bankNumber;
                JdbcControl.setRs(JdbcControl.getStmt().executeQuery(sql));
                if(JdbcControl.getRs().next()){
                    write();//展示题目
                }
            }
        }
    }
}
